<template>
  <Nav>
    {{ $t('union.list') }}
  </Nav>
  <div class="page-union-list">
    <div class="content">
      <div class="search">
        <input v-model="input" type="text" :placeholder="$t('union.search')" />
      </div>
      <div class="page">
        <md-activity-indicator v-if="loading" type="carousel" color="#5d62a7" :size="15"></md-activity-indicator>
      </div>
      <div class="list">
        <div v-for="item in data" class="item" @click="vote.open(item)">
          <div class="icon">
            <img :src="item.logo">
          </div>
          <div class="name wrap">
            {{ item.name }}
          </div>
          <div class="vote">
            {{ item.have_vote }} {{ $t('union.unit') }}
            <div class="asset">{{ $t('union.vote') }}</div>
          </div>
        </div>
      </div>
    </div>
  </div>
  <Vote ref="vote" @confirm="search(input)" />
</template>

<script setup>
import { ref, watch } from 'vue'
import { list } from '@/api/union'
import { toast, dialog } from '@/style'
import { t } from '@/lang'
import Nav from '@/components/nav.vue'
import Vote from './vote.vue'

const input = ref('')
const data = ref([])
const loading = ref(false)
const vote = ref(null)

// 监听input
watch(input, () => {
  search(input.value)
})

// 搜索公会
const search = (title = '') => {
  loading.value = true
  list(title).then(res => {
    data.value = res.data
  }).finally(() => {
    loading.value = false
  })
}

search()
</script>

<style lang="scss" scoped>
  .page-union-list{
    min-height: 100%;
    background: url('@/assets/page.jpg') center center no-repeat;
    background-size: cover;
    background-attachment:fixed;

    .content{
      padding: 130px 30px 30px;
    }

    .search{
      padding: 0 20px;
      margin-bottom: 20px;
      border-radius: 50px;
      background: rgba(255, 255, 255, .15);
      overflow: hidden;

      input{
        width: 100%;
        height: 45px;
        background: 0;
        border: 0;
        color: #fff;
        font-size: 16px; 
        outline: 0;
        text-align: center;

        &::-webkit-input-placeholder { 
          color: #5d62a7; 
        } 
        &:-moz-placeholder { 
          color: #5d62a7; 
        } 
        &::-moz-placeholder { 
          color: #5d62a7; 
        } 
        &:-ms-input-placeholder { 
          color: #5d62a7; 
        }
      }
    }

    .page{
      padding: 20px;
      height: 20px;
      display: flex;
      align-items: center;
      flex-direction: column;
    }

    .list{
      background-image: linear-gradient(to left, #1f235e, #1d0f5e);
      border-radius: 10px;
      overflow: hidden;

      .item{
        padding: 20px;
        line-height: 20px;
        overflow: hidden;

        &:nth-child(1) {
          background: rgba(255, 255, 255, .18)
        }
        &:nth-child(2) {
          background: rgba(255, 255, 255, .16)
        }
        &:nth-child(3) {
          background: rgba(255, 255, 255, .14)
        }
        &:nth-child(4) {
          background: rgba(255, 255, 255, .12)
        }
        &:nth-child(5) {
          background: rgba(255, 255, 255, .1)
        }
        &:nth-child(6) {
          background: rgba(255, 255, 255, .08)
        }
        &:nth-child(7) {
          background: rgba(255, 255, 255, .06)
        }
        &:nth-child(8) {
          background: rgba(255, 255, 255, .04)
        }
        &:nth-child(9) {
          background: rgba(255, 255, 255, .02)
        }
        
        .icon{
          float: left;
          width: 50px;
          height: 50px;
          border-radius: 100%;
          margin-right: 15px;
          overflow: hidden;

          img{
            width: 100%;
            height: 100%;
            object-fit: cover;
          }   
        }

        .name{
          color: rgba(255,255,255,.7);
          font-size: 16px;
          line-height: 25px;
          padding-right: 50px;
        }

        .vote{
          font-size: 14px;
          line-height: 20px; 
          color: #ffc21b;
          padding-top: 3px
        }

        .asset{
          background: #1cd4b6;
          float: right;
          color: #fff;
          font-size: 12px;
          line-height: 18px;
          padding: 5px 10px;
          border-radius: 5px;
          margin-top: -15px;
        }
      }
    }
  }
</style>